package cn.concete;

import cn.Config;
import cn.WorkType;

import java.math.BigDecimal;

/***
 *
 * 小时工，每小时薪资为35元。每月工作160小时，超出部分薪资按照1.3倍发放。
 *
 * */
public class HourWorkTypeConcete implements WorkType {

    private float workHours;

    private float monthWorkTime = 160f;

    private String birthday = null;

    private BigDecimal everHourWorkTimeMoney = Config.everHourWorkTimeMoney;

    public HourWorkTypeConcete(float workHours, String birthday) {
        this.workHours = workHours;
        this.birthday = birthday;
    }

    @Override
    public BigDecimal calc() {
        if (this.workHours <= 0) {
            //没有工作时长,发放工资为 0
            return new BigDecimal("0");
        }
        BigDecimal baseMoney = new BigDecimal("0");
        if (checkToday(this.birthday)) {
            System.out.println("该员工生日,工资额外加：" + Config.birthDayMonty.toString());
            baseMoney = baseMoney.add(Config.birthDayMonty);
        }

        //每月工作160小时，超出部分薪资按照1.3倍发放
        if (this.workHours > this.monthWorkTime) {
            //基础工资加
            //计算多余时长
            float overFlowHours = this.workHours - this.monthWorkTime;
            //先计算 160小时需要支付工资
            //然后计算超出部分需要支付工资
            return baseMoney.add(new BigDecimal(this.monthWorkTime).multiply(everHourWorkTimeMoney).
                    add(everHourWorkTimeMoney.multiply(new BigDecimal(overFlowHours)).
                            multiply(new BigDecimal("1.3"))));
        } else {
            //每月工作 160 或者小于 160
            return baseMoney.add(new BigDecimal(this.workHours).multiply(everHourWorkTimeMoney));
        }
    }
}
